//引入fs模块

const fs = require('fs')

//先读取
fs.readFile('./files/test.txt', 'utf-8', (err, dataStr) => {
  err && console.log(err)

  if (dataStr === '只因你太美') {
    fs.writeFile('./files/test.txt', '露出鸡脚了吧小黑子', 'utf-8', err =>
      err
        ? console.log(err)
        : fs.readFile('./files/test.txt', 'utf-8', (err, dataStr) => console.log(dataStr))
    )
  } else if (dataStr === '露出鸡脚了吧小黑子') {
    fs.writeFile('./files/test.txt', '只因你太美', 'utf-8', err =>
      err
        ? console.log(err)
        : fs.readFile('./files/test.txt', 'utf-8', (err, dataStr) => console.log(dataStr))
    )
  }
})
